<template>
  <div class="index-lists">
    <el-card class="!border-none" shadow="never">
      <el-form ref="formRef" class="mb-[-16px]" :model="queryParams" :inline="true">
        <el-form-item label="社团名称" prop="name">
          <el-input class="w-[280px]" v-model="queryParams.name" placeholder="请输入社团名称"/>
        </el-form-item>
        <el-form-item label="所有者&nbsp;&nbsp;" prop="address">
          <el-input class="w-[280px]" v-model="queryParams.ownerName" placeholder="请输入所有者"/>
        </el-form-item>
        <el-form-item label="状态&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;" prop="status">
          <el-select v-model="queryParams.status" class="w-[280px]" placeholder="请选择状态" clearable>
            <el-option label="待审核" value="0" />
            <el-option label="正常" value="1" />
            <el-option label="不通过" value="2" />
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button type="primary" @click="resetPage">查询</el-button>
          <el-button @click="resetParams">重置</el-button>
        </el-form-item>
      </el-form>
    </el-card>
    <el-card class="!border-none mt-4" shadow="never">
      <el-table class="mt-4" size="large" v-loading="pager.loading" :data="pager.lists">
        <el-table-column label="名称" prop="name" min-width="100" />
        <el-table-column label="logo" min-width="100">
          <template #default="{ row }">
            <image-contain
                v-if="row.logo"
                :src="row.logo"
                :width="60"
                :height="45"
                :preview-src-list="[row.logo]"
                preview-teleported
                fit="contain"
            />
          </template>
        </el-table-column>
        <el-table-column label="封面" min-width="100">
          <template #default="{ row }">
            <image-contain
                v-if="row.cover"
                :src="row.cover"
                :width="60"
                :height="45"
                :preview-src-list="[row.cover]"
                preview-teleported
                fit="contain"
            />
          </template>
        </el-table-column>
        <el-table-column label="状态" prop="status" min-width="100">
          <template #default="{ row }">
            <el-tag v-if="row.status == 0">待审核</el-tag>
            <el-tag type="success" v-else-if="row.status == 1">正常</el-tag>
            <el-tag type="info" v-else-if="row.status == 5">结束</el-tag>
            <el-tag type="danger" v-else-if="row.status == 2">不通过</el-tag>
          </template>
        </el-table-column>
        <el-table-column label="所有者" prop="ownerName" min-width="100" />
        <el-table-column label="创建时间" prop="createTime" min-width="100" />
        <el-table-column label="操作" width="160" fixed="right">
          <template #default="{ row }">
            <el-button
                v-perms="['team/examine']"
                v-if="row.status == 0"
                type="primary"
                link
                @click="handleExamine(row)"
            >
              审核
            </el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="flex justify-end mt-4">
        <pagination v-model="pager" @change="getLists" />
      </div>
    </el-card>
  </div>
</template>
<script lang="ts" setup name="competition">
import { usePaging } from '@/hooks/usePaging'
import type {Action} from "element-plus";
import {ElMessageBox} from "element-plus";
import {teamExamine, teamLists} from "@/api/team";
const showEdit = ref(false)
const queryParams = reactive({
  name: '',
  status: '',
  ownerName: ''
})

const { pager, getLists, resetPage, resetParams } = usePaging({
  fetchFun: teamLists,
  params: queryParams
})

const handleExamine = async (obj: any) => {
  let status = obj.status;
  await ElMessageBox.confirm('审核【'+obj.name+'】的社团管理员是否通过？','温馨提示', {
    distinguishCancelAndClose: true,
    confirmButtonText: '确定',
    cancelButtonText: '拒绝',
    type: 'warning'
  }).then(() => {
    status = 1
  }).catch((action: Action) => {
    console.log(action)
    if(action === 'cancel'){
      status = 2
    }else{
      status = 0
    }
  })
  if(status !=0){
    await teamExamine({ id:obj.id,status:status })
  }
  getLists()
}

getLists()
</script>
